<template>
	<view class="container">
		<view class="card_box">
			<view class="yue">
				<view class="text">
					<view class="small">可用余额（元）</view>
					<view class="big" v-if="userInfo">{{userInfo.memberInfo.balance}}</view>
					<view class="big" v-else>0.00</view>
				</view>
			</view>
			<view class="bottom">
				<view class="all" v-if="userInfo">总金额<text>{{userInfo.memberInfo.balance}}</text>元</view>
				<view class="all" v-else>0.00</view>
				<view class="all">以消费金额<text>{{total}}</text>元</view>
			</view>
		</view>
		<view class="title">资金记录</view>
		<view class="list_box">
			<view class="list" v-for="(item,index) in balanceList">
				<view class="left">
					<view>购买产品</view>
					<view class="time">{{$dTime(item.created)}}</view>
				</view>
				<view class="right">{{item.outcome}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: null,
				balanceList: [],
				total: 0,
			}
		},
		onLoad() {
			this.getUser()
			this.getData()
		},
		methods: {
			getUser() {
				this.$allApi.getUserInfo().then(res => {
					this.userInfo = res.data
				})
			},
			getData() {
				this.$allApi.balanceHistory().then(res => {
					console.log(res);
					this.balanceList = res.data.list
					for (let item of this.balanceList) {
						this.total += Number(item.outcome)
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.list_box {
		padding: 0 30rpx;

		.list {
			height: 140rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-top: 1px solid #eee;

			.time {
				font-size: 24rpx;
				color: #999;
			}

			.right {
				font-size: 32rpx;
				font-weight: bold;
				color: #ff3d37;
			}
		}
	}

	.title {
		padding: 30rpx;
	}

	.card_box {
		width: 690rpx;
		height: 260rpx;
		border-radius: 10rpx;
		margin: 30rpx;
		background: #ff3d37;
		position: relative;

		.yue {
			padding: 30rpx;
			height: 186rpx;
			display: flex;
			align-items: center;
			color: #fff;

			.big {
				font-size: 36rpx;
				font-weight: bold;
			}
		}

		.bottom {
			height: 74rpx;
			background: rgba(0, 0, 0, .05);
			display: flex;
			align-items: center;
			justify-content: space-between;

			.all {
				padding: 0 30rpx;
				font-size: 24rpx;
				color: #fff;

				text {
					font-size: 32rpx;
					font-weight: bold;
				}
			}
		}
	}
</style>